{{ define "csat" }}
{{ template "header" . }}
<div class="csat-container">
    <div class="csat-header">
        <h2>{{ L.T "csat.rateYourInteraction" }}</h2>
    </div>

    <form action="/csat/{{ .Data.CSAT.UUID }}" method="POST" class="csat-form" novalidate>
        <div class="rating-container">
            <div class="rating-options">
                <input type="radio" id="rating-1" name="rating" value="1" required>
                <label for="rating-1" class="rating-option" tabindex="0">
                    <div class="emoji-wrapper">
                        <span class="emoji">😢</span>
                    </div>
                    <span class="rating-text">{{ L.T "csat.rating.poor" }}</span>
                </label>

                <input type="radio" id="rating-2" name="rating" value="2">
                <label for="rating-2" class="rating-option" tabindex="0">
                    <div class="emoji-wrapper">
                        <span class="emoji">😕</span>
                    </div>
                    <span class="rating-text">{{ L.T "csat.rating.fair" }}</span>
                </label>

                <input type="radio" id="rating-3" name="rating" value="3">
                <label for="rating-3" class="rating-option" tabindex="0">
                    <div class="emoji-wrapper">
                        <span class="emoji">😊</span>
                    </div>
                    <span class="rating-text">{{ L.T "csat.rating.good" }}</span>
                </label>

                <input type="radio" id="rating-4" name="rating" value="4">
                <label for="rating-4" class="rating-option" tabindex="0">
                    <div class="emoji-wrapper">
                        <span class="emoji">😃</span>
                    </div>
                    <span class="rating-text">{{ L.T "csat.rating.great" }}</span>
                </label>

                <input type="radio" id="rating-5" name="rating" value="5">
                <label for="rating-5" class="rating-option" tabindex="0">
                    <div class="emoji-wrapper">
                        <span class="emoji">🤩</span>
                    </div>
                    <span class="rating-text">{{ L.T "csat.rating.excellent" }}</span>
                </label>
            </div>
            <!-- Validation message for rating -->
            <div class="validation-message" id="ratingValidationMessage"
                style="display: none; color: #dc2626; text-align: center; margin-top: 10px; font-size: 0.9em;">
                {{ L.Ts "globals.messages.pleaseSelect" "name" "rating" }}
            </div>
        </div>

        <div class="feedback-container">
            <label for="feedback" class="feedback-label">{{ L.T "globals.messages.additionalFeedback" }}</label>
            <textarea id="feedback" name="feedback" placeholder="" rows="6" maxlength="1000"
                onkeyup="updateCharCount(this)"></textarea>
            <div class="char-counter">
                <span id="charCount">0</span>/1000
            </div>
        </div>

        <button type="submit" class="button submit-button">{{ L.T "globals.messages.submit" }}</button>
    </form>
</div>

<script>
    function updateCharCount (textarea) {
        const counter = document.getElementById('charCount');
        const count = textarea.value.length;
        counter.textContent = count;

        const charCounter = counter.parentElement;
        if (count > 900) {
            charCounter.classList.add('near-limit');
        } else {
            charCounter.classList.remove('near-limit');
        }
    }

    // Make sure a rating is selected before submitting the form
    document.querySelector('.csat-form').addEventListener('submit', function (e) {
        const rating = document.querySelector('input[name="rating"]:checked');
        const feedback = document.querySelector('#feedback');
        const validationMsg = document.getElementById('ratingValidationMessage');

        if (!rating) {
            e.preventDefault();
            validationMsg.style.display = 'block';

            // Hide the message after 10 seconds
            setTimeout(() => {
                validationMsg.style.display = 'none';
            }, 10000);
        } else {
            validationMsg.style.display = 'none';
        }
    });

    // Hide validation message when a rating is selected
    document.querySelectorAll('input[name="rating"]').forEach(function (radio) {
        radio.addEventListener('change', function () {
            const validationMsg = document.getElementById('ratingValidationMessage');
            validationMsg.style.display = 'none';
        });
    });
</script>

<style>
    .csat-container {
        background: #fff;
        max-width: 700px;
        margin: 30px auto 15px auto;
    }

    .csat-header {
        text-align: center;
        margin-bottom: 40px;
    }

    .csat-header h1 {
        font-size: 2em;
        color: #1a1a1a;
        margin-bottom: 10px;
    }

    .conversation-subject {
        color: #666;
        font-size: 1.1em;
    }

    .csat-form {
        max-width: 600px;
        margin: 0 auto;
    }

    .rating-container {
        margin-bottom: 40px;
    }

    .rating-options {
        display: flex;
        justify-content: center;
        gap: 15px;
        margin-top: 30px;
        align-items: center;
    }

    .rating-options input[type="radio"] {
        display: none;
    }

    .rating-option {
        display: flex;
        flex-direction: column;
        align-items: center;
        cursor: pointer;
        transition: all 0.3s ease;
        padding: 12px;
        position: relative;
        min-width: 90px;
        flex-shrink: 0;
    }

    .rating-option:hover {
        transform: translateY(-3px);
    }

    .rating-option:focus {
        outline: 2px solid #3b82f6;
        outline-offset: 2px;
        border-radius: 8px;
    }

    .rating-options input[type="radio"]:checked+.rating-option {
        transform: translateY(-3px);
    }


    .emoji-wrapper {
        background: #f8fafc;
        border-radius: 50%;
        width: 65px;
        height: 65px;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-bottom: 8px;
        transition: all 0.3s ease;
        border: 2px solid #e2e8f0;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    }

    .rating-option:hover .emoji-wrapper {
        transform: scale(1.05);
        background: #f1f5f9;
        border-color: #3b82f6;
        box-shadow: 0 4px 8px rgba(59, 130, 246, 0.15);
    }

    .rating-options input[type="radio"]:checked+.rating-option .emoji-wrapper {
        transform: scale(1.05);
        background: #dbeafe;
        border-color: #3b82f6;
        box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    }

    .emoji {
        font-size: 2.2em;
        line-height: 1;
        transform: translateY(1px);
    }

    .rating-text {
        font-size: 0.85em;
        text-align: center;
        color: #64748b;
        font-weight: 500;
        line-height: 1.2;
    }

    .feedback-container {
        margin-bottom: 30px;
    }

    .feedback-label {
        display: block;
        margin-bottom: 10px;
        font-size: 1.1em;
        color: #333;
    }

    textarea {
        width: 100%;
        padding: 15px;
        border: 2px solid #e0e0e0;
        border-radius: 8px;
        font-size: 1em;
        line-height: 1.5;
        resize: vertical;
        transition: border-color 0.3s ease;
    }

    textarea:focus {
        border-color: #3b82f6;
        outline: none;
        box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    }

    .char-counter {
        margin-top: 8px;
        text-align: right;
        color: #666;
        font-size: 0.9em;
    }

    .char-counter.near-limit {
        color: #ff5722;
        font-weight: 500;
    }

    .submit-button {
        width: 100%;
        margin-top: 20px;
        padding: 15px 30px;
        font-size: 1.1em;
        font-weight: 500;
        transition: all 0.3s ease;
    }

    @media screen and (max-width: 600px) {
        .csat-container {
            margin: 0;
            padding: 20px;
            border-radius: 0;
        }

        .rating-options {
            gap: 8px;
        }

        .rating-option {
            min-width: 70px;
            padding: 8px;
        }

        .emoji-wrapper {
            width: 50px;
            height: 50px;
        }

        .emoji {
            font-size: 1.8em;
        }

        .rating-text {
            font-size: 0.8em;
        }
    }

    @media screen and (max-width: 480px) {
        .rating-options {
            gap: 5px;
        }

        .rating-option {
            min-width: 60px;
            padding: 6px;
        }

        .emoji-wrapper {
            width: 45px;
            height: 45px;
        }

        .emoji {
            font-size: 1.6em;
        }

        .rating-text {
            font-size: 0.75em;
        }
    }
</style>
{{ template "footer" }}
{{ end }}